from dataclasses import field, dataclass

# from mocks import get_repository_info as get_repository_info_mock
# from mocks import get_commit_info as get_commit_info_mock
from backend import get_repository_info as get_repository_info_backend
from backend import get_commit_info as get_commit_info_backend


@dataclass
class RepositoryInfo:
    platform: str = field(
        default=None, metadata={"desc": "平台名称，如Github、GitLab等，对于某些平台，有更多信息（Pull Request或Issue）的处理"}
    )
    title: str = field(
        default=None, metadata={"desc": "仓库名称"}
    )
    content: str = field(
        default=None, metadata={"desc": "README.md文件内容"}
    )
    readme_abstract: str = field(
        default=None, metadata={"desc": "README.md文件内容摘要"}
    )


@dataclass
class CommitInfo:
    info: str = field(
        default=None, metadata={"desc": "Commit的描述信息"}
    )
    comments: dict = field(
        default_factory=dict, metadata={"desc": "产生变动部分的注释信息"}
    )


class IssuePRInfo:
    title = None
    labels = None
    body = None

    def __str__(self):
        return str({
            "title": self.title,
            "labels": self.labels,
            "body": self.body
        })


def get_repository_info(repository_id) -> RepositoryInfo:
    json_data = get_repository_info_backend(repository_id)
    info = RepositoryInfo()
    info.platform = json_data["platform"]
    info.title = json_data["name"]
    info.content = json_data["readme"]
    return info


def get_commit_info(repository_id, commit_id):
    json_data = get_commit_info_backend(repository_id, commit_id)
    info = CommitInfo()
    info.info = json_data["info"]
    info.comments = json_data["comments"]
    return info
